//获取应用实例
const app = getApp()

Page({
  /**
   * 页面的初始数据
   */
  data: {
    heightConfig: 0,
    navTop: 0,
    statusBarHeight: getApp().globalData.navTop,
    inputContent: "",
    theme_id: -1,
    article: "",
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      navTop: getApp().globalData.navTop,
      heightConfig: getApp().globalData.windowHeight,
    })

    this.setData({
      article: wx.getStorageSync("priviewHtml")
    })

    if (options.theme_id != null) {
      this.setData({
        theme_id: options.theme_id
      })
    }

  },
  inputContent(e) {
    this.setData({
      inputContent: e.detail.value
    })
  },

  submit() {
    let that = this;
    if (this.data.inputContent.length <= 3) {
      wx.showToast({
        title: '至少三个字',
        icon: 'none',
        image: '',
        duration: 1500,
        mask: false,
      });
      return
    }

    wx.showModal({
      title: '提示',
      content: '确定么',
      showCancel: true,
      cancelText: '取消',
      cancelColor: '#000000',
      confirmText: '确定',
      confirmColor: '#3CC51F',
      success: (result) => {


        if (result.confirm) {
          new Promise(() => {
            wx.request({
              url: getApp().globalData.url + '/saveArticle/',

              data: {
                themeId: that.data.theme_id,
                articleContent: that.data.inputContent,
                imageUrls: that.data.result_image_url
              },
              header: {
                "authorization": wx.getStorageSync("token")
              },
              method: 'POST',
              success: (result) => {
                console.log(result.data)
              },
            });
          })

        }
      },
    });











  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

 
 
})